/*
 * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2006.
 *
 * Licensed under the Aduna BSD-style license.
 */
package edu.tju.rdfbase.repository.store;

import java.io.File;

import edu.tju.rdfbase.model.LiteralFactory;
import edu.tju.rdfbase.model.URIFactory;
import edu.tju.rdfbase.model.ValueFactory;
import edu.tju.rdfbase.model.impl.ValueFactoryImpl;
import edu.tju.rdfbase.repository.Repository;
import edu.tju.rdfbase.repository.RepositoryMetaData;
import edu.tju.rdfbase.store.Store;
import edu.tju.rdfbase.store.StoreException;

/**
 * An implementation of the {@link Repository} interface that operates on a
 * (stack of) {@link Store Store} object(s). The behaviour of the repository is
 * determined by the Store stack that it operates on; for example, the repository
 * will only support RDF Schema or OWL semantics if the Store stack includes an
 * inferencer for this.
 * <p>
 * Creating a repository object of this type is very easy. For example, the
 * following code creates and initializes a main-memory store with RDF Schema
 * semantics:
 * 
 * <pre>
 * Repository repository = new RepositoryImpl(new ForwardChainingRDFSInferencer(new MemoryStore()));
 * repository.initialize();
 * </pre>
 * 
 * Or, alternatively:
 * 
 * <pre>
 * Store storeStack = new MemoryStore();
 * storeStack = new ForwardChainingRDFSInferencer(storeStack);
 * 
 * Repository repository = new Repository(storeStack);
 * repository.initialize();
 * </pre>
 * 
 * @author Arjohn Kampman
 */
public class StoreRepository implements Repository {

	/*-----------*
	 * Constants *
	 *-----------*/

	private final Store store;

	/*--------------*
	 * Constructors *
	 *--------------*/

	/**
	 * Creates a new repository object that operates on the supplied Store.
	 * 
	 * @param store
	 *        A Store object.
	 */
	public StoreRepository(Store store) {
		this.store = store;
	}

	/*---------*
	 * Methods *
	 *---------*/

	public RepositoryMetaData getMetaData()
		throws StoreException
	{
		return new StoreRepositoryMetaData(store.getMetaData());
	}

	public File getDataDir() {
		return store.getDataDir();
	}

	public void setDataDir(File dataDir) {
		store.setDataDir(dataDir);
	}

	public void initialize()
		throws StoreException
	{
		store.initialize();
	}

	public void shutDown()
		throws StoreException
	{
		store.shutDown();
	}

	/**
	 * Gets the Store object that is on top of the Store stack that this repository
	 * operates on.
	 * 
	 * @return A Store object.
	 */
	public Store getStore() {
		return store;
	}

	public LiteralFactory getLiteralFactory() {
		return store.getLiteralFactory();
	}

	public URIFactory getURIFactory() {
		return store.getURIFactory();
	}

	public ValueFactory getValueFactory() {
		return new ValueFactoryImpl(getURIFactory(), getLiteralFactory());
	}

	public StoreRepositoryConnection getConnection()
		throws StoreException
	{
		return new StoreRepositoryConnection(this, store.getConnection());
	}

	public String toString() {
		return store.toString();
	}
}
